//
//  BLActivityZoneViewController.m
//  家校互通
//
//  Created by 李赛 on 15/7/8.
//  Copyright (c) 2015年 姬鑫宇. All rights reserved.
//

#import "BLActivityZoneViewController.h"
#import "ACZoneDetailTableViewCell.h"
#import "ACZoneHeaderTableViewCell.h"
#import "HomeWorkViewController.h"
#import "BLParaEnumParamiter.h"
@interface BLActivityZoneViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) NSMutableArray *activityList;
@end

@implementation BLActivityZoneViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"活动专区";
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:NULL];
    
    self.navigationItem.rightBarButtonItem = buttonItem;
    _contentTableView.delegate=self;
    _contentTableView.dataSource=self;
    _activityList=[[NSMutableArray alloc]initWithCapacity:0];
    [self connect];
    // Do any additional setup after loading the view.
}
-(void)connect
{
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [CoModel getActivitys:^(BOOL result, NSMutableArray *arrayList, NSError *error) {
        if (result) {
           [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
            _activityList =[NSMutableArray arrayWithArray:arrayList];
            [_contentTableView reloadData];
        }
    } withtoken:[DSFUserInfo shareUserInstance].token clazzId:[DSFUserInfo shareUserInstance].clazz_user.clazz.id withPageNumber:0 withPageSize:5];
}

#pragma mark -UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }else
    {
        return _activityList.count;
    }
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
     
        ACZoneHeaderTableViewCell *vCell=[tableView dequeueReusableCellWithIdentifier:@"ACZoneHeaderTableViewCell" forIndexPath:indexPath];
        if (_activityList.count) {
            [vCell setBlackBoardModel:[_activityList objectAtIndex:indexPath.row]];
        }
        UIView *selectView=[[UIView alloc]initWithFrame:vCell.frame];
        selectView.backgroundColor=COLOR(240, 240, 240);
        vCell.selectedBackgroundView=selectView;
        return vCell;
    }else
    {
        BlackBoardModel *model=[_activityList objectAtIndex:indexPath.row];
        ACZoneDetailTableViewCell *vCell=[tableView dequeueReusableCellWithIdentifier:@"ACZoneDetailTableViewCell" forIndexPath:indexPath];
        UIView *selectView=[[UIView alloc]initWithFrame:vCell.frame];
        [vCell setContentOfBlackBoard:model];
        selectView.backgroundColor=COLOR(240, 240, 240);
        vCell.selectedBackgroundView=selectView;
        return vCell;

    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return nil;
}
#pragma mark -UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        return 50;
    }else
    {
        return 115;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.001;
}
// Called after the user changes the selection.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
       [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
        if (indexPath.section == 1) {
            
            BlackBoardModel *model=[_activityList objectAtIndex:indexPath.row];
            HomeWorkViewController *vc = [self.storyboard  instantiateViewControllerWithIdentifier:@"HomeWorkViewController"];
            vc.viewControllerTag=BLViewControllerTagForActivity;
          
            
            vc.blackboardId = [NSString stringWithFormat:@"%ld",(long)model.id];
            
            [self.navigationController pushViewController:vc animated:YES];
        }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
